---
id: qr-code
title: QR Code
description: A component that generates a QR code based on the provided data.
---

<ComponentPreview id="QrCode" />

## Anatomy

To set up the QR code correctly, you'll need to understand its anatomy and how we name its parts.

> Each part includes a `data-part` attribute to help identify them in the DOM.

<Anatomy id="qr-code" />

## Examples

Learn how to use the `QR Code` component in your project. Let's take a look at the most basic example:

<Example id="basic" />

### With Overlay

You can also add a logo or overlay to the QR code. This is useful when you want to brand the QR code.

<Example id="with-overlay" />

### Error Correction

In cases where the link is too long or the logo overlay covers a significant area, the error correction level can be
increased.

Use the `encoding.ecc` or `encoding.boostEcc` property to set the error correction level:

- `L`: Allows recovery of up to 7% data loss (default)
- `M`: Allows recovery of up to 15% data loss
- `Q`: Allows recovery of up to 25% data loss
- `H`: Allows recovery of up to 30% data loss

<Example id="error-correction" />

### Using the Root Provider

The `RootProvider` component provides a context for the QR code. It accepts the value of the `useQrCode` hook. You can
leverage it to access the component state and methods from outside the QR code.

<Example id="root-provider" />

> If you're using the `RootProvider` component, you don't need to use the `Root` component.

## Guides

### Download a QR Code

You can download the QR code by using the `QrCode.DownloadTrigger`. You will have to provide the `fileName` and the
`mimeType` of the image.

```tsx
<QrCode.DownloadTrigger fileName="qr-code.png" mimeType="image/png">
  Download
</QrCode.DownloadTrigger>
```

## API Reference

### Props

<ComponentTypes id="qr-code" />

### Context

These are the properties available when using `UqrUcode.Context`, `useUqrUcodeContext` hook or `useUqrUcode` hook.

<ContextType id="qr-code" />
